package info.nixbear.tgcms.admin.client.place;

import info.nixbear.tgcms.admin.shared.request.PageProxy;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;

public class PagesPlace extends Place {
	
	public static class PageEditPlace extends PagesPlace {
		String token;
		PageProxy page;
		
		public PageEditPlace(String token, PageProxy page) {
			this.token = token;
			this.page = page;
		}

		public String getToken() {
			return token;
		}
		
		public PageProxy getPage() {
			return page;
		}
		
		public static final String newPageToken = "new";
		
		public boolean isTokenANewPageToken() {
			return newPageToken.equals(token);
		}
	}
	
	@Prefix("pages")
	public static class Tokenizer implements PlaceTokenizer<PagesPlace> {

		@Override
		public PagesPlace getPlace(String token) {
			return (token==null || token.isEmpty())?new PagesPlace():new PageEditPlace(token, null);
		}

		@Override
		public String getToken(PagesPlace place) {
			return (place instanceof PageEditPlace)?((PageEditPlace) place).getToken():"";
		}
		
	}

}
